﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Micro.AspNetCore.ApiWidgets
{

    public class ApiResult<TResult> : ApiResult, IApiResult<TResult>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ApiResult{TResult}"/> class.
        /// </summary>
        public ApiResult() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="ApiResult{TResult}" /> class.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="statusCode">The status code.</param>
        public ApiResult(TResult result, int code, int? statusCode=null, int? dataCount = 0, string message = "")
        {
            if (!statusCode.HasValue)
            {
                statusCode = code == 0 ? 200 : 400;
            }
            StatusCode = statusCode ?? 200;
            Code = code;
            IsSuccess = Code == 0;
            Message = message;
            Data = result;
            DataCount = dataCount.Value;
        }

        /// <summary>
        /// Gets or sets the result.
        /// </summary>
        /// <value>The result.</value>
        public TResult Data { get; set; }
    }
}
